<template>
  <div class="sub-menu-box">
    <template v-for="item in list">
      <el-submenu v-if="item.children" :key="item.id" :index="item.id+''">
        <template slot="title">
          <span>{{ item.name }}</span>
        </template>
        <sub-meun :list="item.children" />
      </el-submenu>
      <el-menu-item v-else :key="item.id" :index="item.id+''" @click="open(item)">
        {{ item.name }}
      </el-menu-item>
    </template>
  </div>
</template>

<script>
export default {
  name: 'SubMeun',
  props: {
    list: {
      type: Array,
      default: () => []
    }
  },
  // 调用祖先的方法
  inject: ['open']
}
</script>

<style>
.sub-menu-box{
  padding-left: 20px;
}
</style>
